import random, os

setGlobalDuration(-1)

a = genWaveform()
b = genWaveform([1,.2,0,.1,0,0,.1])

randomi(bus='pit', mini=.95, maxi=1.05, rate=5)
lfo(bus='amp', frequency=.2, amplitude=.4)

if '/Ounk.app' not in os.getcwd():
    myfile = os.path.join(os.getcwd(), 'doc', 'examples', 'myOrch.txt')
else:
    myfile = os.path.join(os.getcwd(), '..', '..', '..', 'doc', 'examples', 'myOrch.txt')

beginPythonInst()
myInstrument(myfile, duration=1, argslist=[5000,200,a,b], vardict={'pit':'pit', 'amp': 'amp'}, out=1)
endPythonInst()

resonator(input=1, pitch=[102,204,301,403,502], amplitude=.5, feedback=.99)

proc = startCsound()

def note():
    dict = {}
    dict['myInstrument'] = {}
    dict['myInstrument']['p3'] = random.randint(2,8)
    dict['myInstrument']['p5'] = random.randint(50,200)
    sendEvent(voice=1, dict=dict, process=proc)

tempo = .5
a = pattern(time=tempo, function=note)

a.start()
a.play()